{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/dengyunfei/miniconda3/envs/torch24/lib/python3.11/site-packages/transformers/models/marian/tokenization_marian.py:175: UserWarning: Recommended: pip install sacremoses.\n",
      "  warnings.warn(\"Recommended: pip install sacremoses.\")\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<transformers.pipelines.text2text_generation.TranslationPipeline at 0x7b4ff765cf90>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from transformers import AutoTokenizer, pipeline\n",
    "pipe = pipeline(\"translation_en_to_zh\", model=\"/media/dengyunfei/6T/data/models/huggingface/opus-mt-en-zh\",device=0)\n",
    "# tokenizer = AutoTokenizer.from_pretrained(\"t5-small\")\n",
    "# model = AutoModelForTranslation.from_pretrained(\"t5-small\")\n",
    "pipe\n",
    "# pipe(\"I am a happy little girl\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'translation_text': '来源: 英国目标群体: 中文 OPUS 目标组: eng-zho 模型: 变压器源语言: eng 目标语言: cjy_Hans cjy_Hant cmn cmn_Hans cmn_Hant lzh_Hans gan lzh lzh_Hans nan wuuu yue yue_Hans yue_Hant 模型: 变压器预处理: 常规 + 句子Piece (spm32k,spm32k) 需要以( = 有效目标语言 ID) 下载原始重量( Opus-2020-07-17.zip 测试集翻译: Opus-2020- 07-17. test.txt 测试计数: Opus-2020- 07-17.eval.txt'}]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from transformers.pipelines.text2text_generation import TranslationPipeline\n",
    "text = \"\"\"\n",
    "source group: English\n",
    "target group: Chinese\n",
    "OPUS readme: eng-zho\n",
    "model: transformer\n",
    "source language(s): eng\n",
    "target language(s): cjy_Hans cjy_Hant cmn cmn_Hans cmn_Hant gan lzh lzh_Hans nan wuu yue yue_Hans yue_Hant\n",
    "model: transformer\n",
    "pre-processing: normalization + SentencePiece (spm32k,spm32k)\n",
    "a sentence initial language token is required in the form of >>id<< (id = valid target language ID)\n",
    "download original weights: opus-2020-07-17.zip\n",
    "test set translations: opus-2020-07-17.test.txt\n",
    "test set scores: opus-2020-07-17.eval.txt\n",
    "\"\"\"\n",
    "pipe(text)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "torch24",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
